package org.redmagic.controller;

import javax.servlet.http.HttpServletRequest;

import org.redmagic.api.BulkService;
import org.redmagic.common.MagicRequest;
import org.redmagic.common.MagicResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping(value = "/bulk")
public class BulkController {
	
	private static final Logger LOGGER = LoggerFactory.getLogger(BulkController.class);
	
	@Autowired
	private BulkService magicService;

	@RequestMapping(value = "/", method = RequestMethod.POST)
	@ResponseBody
	public MagicResponse findProperties(@RequestBody MagicRequest magicRequest, HttpServletRequest servletRequest) {
		String remoteHost = servletRequest.getRemoteHost();
		LOGGER.info("Request: {}", magicRequest);
		LOGGER.info("Host: {}", remoteHost);
		
		return magicService.resolvePlaceholders(magicRequest, remoteHost);
	}
	
}
